<?php
session_start();
include 'db_con.php';
require "functions.php";

if (isUserLoged()) {
	header("Location: index.php");
	die();
}
if(isset($_POST['register']))
{
	header("Location: register.php");
	die();
}

?>
<!DOCTYPE html>
<html>
<head>
<title>Traktors login page</title>
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>
<body>
<div id="wrapper">
	<div id="login">
		<form method="post" action="login.php">
			<p>Username: <input type="text" name="username" /></p>
			<p>Password: <input type="password" name="password" /></p>
			<p><input type="submit" name="submit" value="Login" /></p>
		</form>
		<?php 		
		if($_POST)
		{
			if(validateUser($_POST['username'], $_POST['password']))
			{
				$_SESSION['username'] = $_POST['username'];
				header("Location: index.php");
				die();
			}
			else
			{
				echo "<p class=\"warning\">Invalid usrname and/or password!</p>";	
			}
		}
		?>
		<p>Don't have an account? <a href="register.php">Sign Up!</a></p>
	</div>
</div>
</body>
</html> 